418dc3d913ec1a1c0443ab6f594696ddbe9b8796,portal-impl/src/com/liferay/portlet/messageboards/service/impl/MBThreadLocalServiceImpl.java,MBThreadLocalServiceImpl,moveThread,#number#number#number#,364

Before Change


		MBCategory oldCategory = mbCategoryPersistence.findByPrimaryKey(
			oldCategoryId);

		MBCategory category = mbCategoryPersistence.findByPrimaryKey(
			categoryId);

		// Messages

After Change



		MBCategory category = null;

		if (categoryId != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
			category = mbCategoryPersistence.findByPrimaryKey(
				categoryId);
		}

		// Messages

		List<MBMessage> messages = mbMessagePersistence.findByG_C_T(
			groupId, oldCategoryId, thread.getThreadId());

		for (MBMessage message : messages) {
			message.setCategoryId(categoryId);

			mbMessagePersistence.update(message, false);

			// Indexer

			if (!message.isDiscussion()) {
				Indexer indexer = IndexerRegistryUtil.getIndexer(
					MBMessage.class);

				indexer.reindex(message);
			}
		}

		// Thread

		thread.setCategoryId(categoryId);

		mbThreadPersistence.update(thread, false);

		// Category

		if (oldCategory != null) {
			oldCategory.setThreadCount(oldCategory.getThreadCount() - 1);
			oldCategory.setMessageCount(
				oldCategory.getMessageCount() - messages.size());

			mbCategoryPersistence.update(oldCategory, false);
		}

		if (category != null) {
			category.setThreadCount(category.getThreadCount() + 1);
			category.setMessageCount(
				category.getMessageCount() + messages.size());